/*
 * author      : dormi330
 * date        : 2018/6/26
 * project     : mybatis
 * description : adaptor 物流服务
 */

package com.deep.trade.adaptor.required.logistical;

import com.deep.trade.adaptor.required.MemberAddress;
import com.deep.trade.adaptor.required.sku.Sku;
import com.deep.trade.common.DateUtils;
import com.deep.trade.order.dto.OutDtoLogisticalRecord;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class LogisticalServiceMock implements LogisticalService {

    static List<OutDtoLogisticalRecord> mockList;

    static {
        mockList = Arrays.asList(
                new OutDtoLogisticalRecord(null, DateUtils.daysAfterNow(-2), "卖家发货"),
                new OutDtoLogisticalRecord(null, DateUtils.daysAfterNow(-1), "广州转运中心已收入"),
                new OutDtoLogisticalRecord(null, new Date(), "【广州市】正在派送, 派件员:张三丰 18612345678")
        );
    }

    /**
     * 运费计算 = f(sku, 数量, 发货地址, 收货地址)
     *
     * @param sku       sku
     * @param qty       数量
     * @param toAddress 收货地址
     * @return
     */
    public BigDecimal freightOfSku(Sku sku, int qty, MemberAddress toAddress) {
        return new BigDecimal("1");
    }

    public BigDecimal freightOfSku(String skuId, int qty, MemberAddress toAddress) {
        return new BigDecimal("1");
    }

    @Override
    public List<OutDtoLogisticalRecord> listOfTrackingNo(String logisticsOrderId) {
        return mockList
                .stream()
                .map(record -> new OutDtoLogisticalRecord(logisticsOrderId, record.getDate(), record.getAction()))
                .collect(Collectors.toList());
    }
}
